﻿using System;
using System.Collections;
using RAP.Framework.Libary.Utils;

namespace RAP.Framework.Libary.DomTemplateBuilder.Handler.TimeIterate
{
  /// <summary>
  /// 周时间迭代器的Handler
  /// </summary>
  public class WeekIterateHandler : TimeIterateBaseHandler
  {
    protected override IList CreateTimeList(DateTime startDate, DateTime endDate)
    {
      var listTimes = new ArrayList();
      var endWeekId = endDate.WeekId();
      var weekNow = DateTime.Now.WeekId();
      for (var date = startDate; date.WeekId() <= endWeekId; date = date.NextWeek())
      {
        listTimes.Add(new Hashtable()
        {
          {
            TIME_ID_FIELD, date.WeekId ( )
          },
          {
            WEEK_FIELD, date.DayOfWeek
          },
          {
            MONTH_ID_FIELD, date.MonthId ( )
          },
          {
            MONTH_FIELD, date.Month
          },
          {
            QUARTER_ID_FIELD, date.QuarterId ( )
          },
          {
            QUARTER_FIELD, date.Quarter ( )
          },
          {
            YEAR_ID_FIELD, date.Year
          },
          {
            START_DATE_FIELD, date.WeekFirstDay ( ).NotLessThan ( startDate ).ToString( "yyyy-MM-dd" )
          },
          {
            END_DATE_FIELD, date.WeekEndDay ( ).NotGreaterThan ( endDate ).ToString( "yyyy-MM-dd" )
          },
          {
            IS_CURRENT_TIME_FIELD, date.WeekId() == weekNow
          }
        });
      }
      return listTimes;
    }
  }
}
